package com.controller;

import com.dto.BookCollectionDTO;
import com.dto.BookRecommendDTO;
import com.service.BookCollectionServiceImpl;
import com.service.LoginServiceImpl;
import com.util.Result;
import com.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linyukun
 * @date 2022/8/8 18:40
 */
@RequestMapping("book/collection")
@RestController
public class BookCollectionController {
    @Autowired
    private LoginServiceImpl loginServiceImpl;

    @Autowired
    private BookCollectionServiceImpl bookCollectionServiceImpl;


    /**
     * 添加图书推荐
     * @author linyukun
     * @date 2022-07-09 10:36
     */
    @RequestMapping(value="/addBookCollection",method = RequestMethod.POST)
    public Result addBookCollection(@RequestBody BookCollectionDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setCreateUser(userName);
            return ResultUtil.returnDataSuccess(bookCollectionServiceImpl.addBookCollection(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 获取图书推荐列表
     * @author linyukun
     * @date 2022-07-09 10:36
     */
    @RequestMapping(value="/getBookCollectionList",method = RequestMethod.POST)
    public Result getBookCollectionList(@RequestBody BookCollectionDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setCreateUser(userName);
            return ResultUtil.returnDataSuccess(bookCollectionServiceImpl.getBookCollectionList(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 删除某个书单
     * @author linyukun
     * @date 2022-07-09 10:36
     */
    @RequestMapping(value="/delBookCollectionById",method = RequestMethod.POST)
    public Result delBookCollectionById(@RequestBody BookCollectionDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setDeleteUser(userName);
            return ResultUtil.returnDataSuccess(bookCollectionServiceImpl.delBookCollectionById(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

}
